import { SDKState, ResultCallback, BannerDir, FunctionType } from "../SDKConfig";
import BaseChannel from "./BaseChannel";
/**
 * 所有广告的父类
 * 
 */
export default abstract class BaseAd {
    //广告状态
    protected state: SDKState = SDKState.close;
    //当前使用的广告ID
    protected adUnitID: string = ''
    //游戏逻辑状态
    protected logicState: SDKState = SDKState.open
    //当前广告实例
    protected instance: any = null;
    //广告实例保存位置
    protected instanceMap = {}

    //连续点击次数
    protected clickCount: number = 0;

    //广告展示次数
    protected showCount: number = 0

    protected callback: any;
    protected channel: BaseChannel;

    protected funcMap: Function[] = []

    constructor(channel: BaseChannel) {
        this.channel = channel;
        this.funcMap[FunctionType.onLoad] = this.onLoad.bind(this)
        this.funcMap[FunctionType.onError] = this.onError.bind(this)
        this.funcMap[FunctionType.onClose] = this.onClose.bind(this)
        this.funcMap[FunctionType.onResize] = this.onResize.bind(this)
        this.funcMap[FunctionType.onHide] = this.onHide.bind(this)
    }

    onHide() {

    }

    getFunc(t: FunctionType) {
        if (!this.funcMap[t]) {
            console.error(' get Func  t ', t)
        }
        return this.funcMap[t]
    }

    setState(s: SDKState) {
        this.state = s;
    }
    setCallback(func: (r: number) => void) {
        this.callback = func;
    }
    getState() {
        return this.state;
    }

    protected dir: BannerDir = BannerDir.BOTTOM_LEFT;

    setDir(dir: BannerDir) {
        this.dir = dir;
    }

    updateSize() {

    }
    abstract open(adID: string, callback?: Function)

    close() {

    }

    show() {

    }

    onLoad() {

    }

    load(isShow?: any) {

    }

    reportAdClick(adId) { }

    reportAdShow(adId) { }

    preload() {
    }

    onResize(data) {

    }

    onError(err) {

    }

    onClose(res?) {

    }


    hide() {

    }

    destroy() {

    }

}